package com.eff.android.lib.ui;

import java.util.List;

import com.eff.android.lib.R;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ECustomAdapter extends BaseAdapter{

	Context context;
	List<ERowItem> rowItems;
	
	public ECustomAdapter(Context context, List<ERowItem> rowItems){
		this.context = context;
		this.rowItems = rowItems;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return rowItems.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return rowItems.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return rowItems.indexOf(getItem(position));
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		if (convertView == null) {
            LayoutInflater mInflater = (LayoutInflater) context
                    .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            convertView = mInflater.inflate(R.layout.list_item, null);
        }

        ImageView imgIcon = (ImageView) convertView.findViewById(R.id.eImage);
        TextView txtTitle = (TextView) convertView.findViewById(R.id.title);

        ERowItem row_pos = rowItems.get(position);
        // setting the image resource and title
        imgIcon.setImageBitmap(row_pos.getIcon());
        txtTitle.setText(row_pos.getTitle());

        return convertView;
	}

}
